package com.tanhua.manage.listener;

import com.alibaba.fastjson.JSON;
import com.tanhua.domain.db.UserInfo;
import com.tanhua.dubbo.api.UserInfoApi;
import com.tanhua.manage.service.UserService;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Map;

@RocketMQMessageListener(topic = "freeze",consumerGroup = "freeze-consumer")
@Component
public class FreezeListener implements RocketMQListener<String> {

    @Autowired
    private UserService userService;
    @Autowired
    private RedisTemplate redisTemplate;
    @Reference
    private UserInfoApi userInfoApi;

    @Override
    public void onMessage(String message) {
        Map<String, String> map= JSON.parseObject(message, Map.class);
        Long userId = Long.parseLong(map.get("userId"));
        //Integer freezeTime = Integer.valueOf(map.get("freezeTime"));
        UserInfo userInfo = userInfoApi.findById(userId);
        userInfo.setUserStatus("1");
        userInfoApi.update(userInfo);
    }
}
